﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using landlord2.Properties;

namespace landlord2
{
    /// <summary>
    /// OptionWindow.xaml 的交互逻辑
    /// </summary>
    public partial class OptionWindow : Window
    {
        private int m_cardStyle;
        private int m_background;
        private int m_bgm;
        private int m_cardsortmode;

        public OptionWindow()
        {
            InitializeComponent();
            ShowSettings();
        }

        public EventHandler OnApplySetting;

        private void ShowSettings()
        {
            switch (Settings.Default.CardStyle)
            {
                case 0: radCardStyle1.IsChecked = true; break;
                case 1: radCardStyle2.IsChecked = true; break;
                case 2: radCardStyle3.IsChecked = true; break;
                case 3: radCardStyle4.IsChecked = true; break;
            }
            switch (Settings.Default.Background)
            {
                case 0: radBackground1.IsChecked = true; break;
                case 1: radBackground2.IsChecked = true; break;
                case 2: radBackground3.IsChecked = true; break;
                case 3: radBackground4.IsChecked = true; break;
                case 4: radBackground5.IsChecked = true; break;
            }
            switch (Settings.Default.BGM)
            {
                case 1: radBGM1.IsChecked = true; break;
                case 2: radBGM2.IsChecked = true; break;
                case 3: radBGM3.IsChecked = true; break;
                case 4: radBGM4.IsChecked = true; break;
            }
            chkSortCardMode.IsChecked = Settings.Default.CardSortMode != 0;
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (radCardStyle1.IsChecked ?? false) m_cardStyle = 0;
            else if (radCardStyle2.IsChecked ?? false) m_cardStyle = 1;
            else if (radCardStyle3.IsChecked ?? false) m_cardStyle = 2;
            else if (radCardStyle4.IsChecked ?? false) m_cardStyle = 3;

            if (radBackground1.IsChecked ?? false) m_background = 0;
            else if (radBackground2.IsChecked ?? false) m_background = 1;
            else if (radBackground3.IsChecked ?? false) m_background = 2;
            else if (radBackground4.IsChecked ?? false) m_background = 3;
            else if (radBackground5.IsChecked ?? false) m_background = 4;

            if (radBGM1.IsChecked ?? false) m_bgm = 1;
            if (radBGM2.IsChecked ?? false) m_bgm = 2;
            if (radBGM3.IsChecked ?? false) m_bgm = 3;
            if (radBGM4.IsChecked ?? false) m_bgm = 4;

            m_cardsortmode = (chkSortCardMode.IsChecked ?? false) ? 1 : 0;
            
            Close();
            if (OnApplySetting != null) OnApplySetting(this, null);
        }

        public int CardStyle
        {
            get
            {
                return m_cardStyle;
            }
        }

        public int BackgroundIndex
        {
            get
            {
                return m_background;
            }
        }

        public int BGM
        {
            get
            {
                return m_bgm;
            }
        }

        public int CardSortMode
        {
            get
            {
                return m_cardsortmode;
            }
        }
    }
}
